package com.shiyi.design.composite;

/**
 * @author wangzhanshuai
 * @date 2021/2/2 5:14 下午
 * @since 1.0
 */
public class Client {

    public static void main(String[] args) {
        BranchNode root = new BranchNode("root");
        LeafNode l1 = new LeafNode("l1");
        BranchNode d1 = new BranchNode("d1");
        root.addNode(l1);
        root.addNode(d1);

        BranchNode d11 = new BranchNode("d11");
        LeafNode l111 = new LeafNode("l111");
        d11.addNode(l111);
        BranchNode d12 = new BranchNode("d12");
        d1.addNode(d11);
        d1.addNode(d12);

        tree(root, 0);

    }

    public static void tree(Node node, int deep) {
        for (int i = 0; i < deep; i++) {
            System.out.print("  |");
        }

        node.print();
        if(!node.isLeaf()) {
            for (Node n : ((BranchNode) node).getNodeList()) {
                tree(n, deep + 1);
            }
        }
    }
}
